/**
 * Copyright (c) 2015, 59store. All rights reserved.
 */
package com.spring.boot.mybatis;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.Reader;

/**
 * @author <a href="mailto:guopf@59store.com">任之</a>
 * @version 1.0 15/11/14
 * @since 1.0
 */
public class MybatisSession {

    public SqlSession getSession() {
        SqlSessionFactoryBuilder builder = new SqlSessionFactoryBuilder();
        SqlSessionFactory factory = null;
        try {
            Reader reader = Resources.getResourceAsReader("MyBatisConfiguration.xml");
            factory = builder.build(reader);
        } catch (Exception e) {
            e.printStackTrace();
        }

        //参数如果为true，表示该会话具有自动提交事务的功能，否则需程序员手动提交事务。
        SqlSession session = factory.openSession(false);
        return session;
    }

}
